import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class O48 {
    public static void main(String[] args) {
        O48 o = new O48();
        System.out.println(o.lengthOfLongestSubstring("abba"));
    }
    public int lengthOfLongestSubstring(String s) {
        if (s.length()==1)
            return 1;
        char[] chs = s.toCharArray();
        Map<Character,Integer> map = new HashMap<>();
        int max = 0;
        int last = 0;
        for (int i = 0; i < chs.length; i++) {
            if (map.containsKey(chs[i])){
                if (max==0)
                    max = i;
                else {
                    max = Math.max(max,i-last);
                }
                last = Math.max(last,map.get(chs[i])+1);
            }
            map.put(chs[i],i);
        }
        return Math.max(max,s.length()-last);
    }
}
